/**
 * Copyright (c) 2020, Mr.Wang (recallcode@aliyun.com) All rights reserved.
 */

package com.cpipec.demo.common;

import cn.com.spic.demo.api.EmployeeService;
import cn.com.spic.demo.dto.EmployeeDTO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cpipec.demo.spi.EOSServerRestClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("${api.version}/permission")
public class PassPermissionController {

	@Autowired
	private EOSServerRestClient eosServerRestClient;
	@Autowired
	private EmployeeService employeeService;
	/**
	 * 获取当前登录用户信息
	 */
	@RequestMapping("/me")
	public Object me() {
		JSON json=eosServerRestClient.getCurrentUser();
		JSONObject object = JSONObject.parseObject(json.toJSONString());
		EmployeeDTO employee = employeeService.getEmployeeById(object.getString("username"));
		object.put("orgcode",employee.getOrgCode());
		object.put("professional",employee.getProfessional());
		return object;
	}

	/**
	 * 获取当前登录用户菜单
	 */
	@RequestMapping("/menu")
	public Object menu() {
		return eosServerRestClient.getUserMenu();
	}
}
